package com.algo.pattern.observable.queue;

import com.algo.pattern.observable.model.StockUpdateMessage;

import java.util.concurrent.ArrayBlockingQueue;

public class StockUpdateQueueManagerImpl implements StockUpdateQueueManager {

    private StockUpdateQueueManagerImpl(){}

    private static final StockUpdateQueueManagerImpl INSTANCE = new StockUpdateQueueManagerImpl();

    public static StockUpdateQueueManagerImpl getInstance() {
        return INSTANCE;
    }

    private ArrayBlockingQueue<StockUpdateMessage> queue = new ArrayBlockingQueue(1000);

    public void put(StockUpdateMessage message) {
        queue.add(message);
        System.out.println("添加消息到队列成功，message=" + message);
    }

    public StockUpdateMessage take() throws InterruptedException {
        return queue.take();
    }

}
